package com.chat.login.Listener;

import com.chat.common.common.constant.ExchangeNameConstant;
import com.chat.common.pojo.EmailRequest;
import com.chat.login.service.AuthService;
import com.chat.login.service.MailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class mailRabbitListener {

    @Autowired
    MailService mailService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "E-Chat.mail.topic.queue"),
            exchange = @Exchange(name = ExchangeNameConstant.ECHAT_MAIL_TOPIC_EXCHANGE, type = ExchangeTypes.TOPIC),
            key = {"#.Email"}
    ))
    public void listenTopicQueue11(EmailRequest emailRequest){
        System.out.println("消费者接收到消息：【" + emailRequest.toString() + "】");
        mailService.sendEmail(emailRequest);
    }
}
